#include "key_menu.h"
#include "main.h"

/**
  * @brief 获取按键值
  * @param  无
  * @retval KeyNum,要读取的按键值
  */
uint8_t get_key_num(void)
{
	uint8_t KeyNum = 0;							//默认为0,没有按键按下返回0
	if(HAL_GPIO_ReadPin(GPIOE,GPIO_PIN_4) == 0)//读取key0口的输入,如果按下(0)
	{
		HAL_Delay(50);							//按键消抖
		while(HAL_GPIO_ReadPin(GPIOE,GPIO_PIN_4) == 0);//直到松手往下走
		HAL_Delay(50);							//按键消抖
		KeyNum = 1;								//返回键码1
	}
    
    
    if(HAL_GPIO_ReadPin(GPIOE,GPIO_PIN_3) == 0)//读取key1口的输入,如果按下(0)
	{
		HAL_Delay(50);							//按键消抖
		while(HAL_GPIO_ReadPin(GPIOE,GPIO_PIN_3) == 0);//直到松手往下走
		HAL_Delay(50);							//按键消抖
		KeyNum = 2;								//返回键码2
	}
    
    
    if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0) == 1)//读取keyu口的输入,如果按下(0)
	{
		HAL_Delay(50);							//按键消抖
		while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0) == 1);//直到松手往下走
		HAL_Delay(50);							//按键消抖
		KeyNum = 3;								//返回键码3
	}

	return KeyNum;
}

